package com.itheima.askme.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.askme.entity.Question;
import com.itheima.askme.query.QuestionQuery;
import com.itheima.askme.service.IQuestionService;
import com.itheima.askme.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dafei
 * @since 2022-06-14
 */
@RestController
@RequestMapping("questions")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;

    @GetMapping("/query")
    public JsonResult query(QuestionQuery query){
        Page<Question> pag=questionService.queryPage(query);
        return  JsonResult.success(pag);
    }

    @PostMapping("/add")
    public JsonResult add(Question query){
        query.setStatus(Question.STATUS_SOLVED);
        query.setCreateTime(new Date());
        questionService.save(query);
        return  JsonResult.success();
    }

}
